$(document).ready(function() {
    $('#registerForm').on('submit', function(e) {
        e.preventDefault();
        
        const userData = {
            userName: $('#userName').val(),
            password: $('#password').val(),
            role: parseInt($('#role').val())
        };

        $.ajax({
            url: '/api/user/register',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(userData),
            success: function(response) {
                if (response.code === 200) {
                    alert('注册成功！');
                    window.location.href = 'index.html';
                } else {
                    alert(response.message);
                }
            },
            error: function(xhr) {
                alert('注册失败，请重试');
            }
        });
    });
}); 